﻿@model IEnumerable<zy1.Models.ProInfo>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>
<form method="get" class="form-inline text-center" style="margin:10px">
    物资类型:@Html.DropDownList("ID", null, new { @class = "form-control" })
    物资名称:<input type="text" name="Name" class="form-control" placeholder="请输入内容" />
    <input type="submit" value="查询" class="btn-primary" />

    @Html.ActionLink("添加", "Create", null, new { @class = "btn btn-primary" })
</form>

<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.ID)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>

        <th>
            @Html.DisplayNameFor(model => model.AddTime)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.IsDestroy)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Unit)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Price)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Description)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.ProType.Name)
        </th>

        <th>操作</th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.ID)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>

            <td>
                @Html.DisplayFor(modelItem => item.AddTime)
            </td>
            <td>
                @(item.IsDestroy==false?"未报废":"已报废")
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Unit)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Price)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Description)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.ProType.Name)
            </td>
            <td>
                @if (item.IsDestroy == false)
                {
                    <a href="#" data-edit="@item.ID">报废</a>
                }

            </td>
        </tr>
    }
</table>
@section scripts{
    <script type="text/javascript">
        $(function () {
            $("a[data-edit]").click(function () {
                var $this = $(this);
                var id = $this.attr("data-edit");
                if (!confirm("确定要报废编号为" + id + "物资吗？")) return;
                $.post("@Url.Content("~/Default/Delete")", { id: id },function(res){
                    if(res==true){
                    location.reload();
                    }

                })


            })
       })

    </script>

}